<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Cart extends CI_Controller{
    public function __construct(){
        parent::__construct();
        @session_start();
    }
    public function set_common(){
        $this->$web_config = $this->config->item('web');
    }

    public function index(){
        $this->load->view(THEME_PATH . '/home.php', $data);
    }

    public function add_cart_action(){
        $common = $this->config->item('web');
        $pro_id = (int)$this->input->post('pro_id',true);
        asdfasdfasdfasdfasdfasdfasdfasdf
        asdfasdfasasdfasd
        $product= $this->data->get_one('ca_product',"pro_id='$pro_id'");
        $qty    = mt_rand(1,10);
        $where  = "member_id='{$_SESSION['web']['member']['member_id']}' and pro_id='$pro_id'";
        if($this->data->get_row_count('ca_shopping_cart',$where)){
            $cart=$this->data->get_one('ca_shopping_cart',$where);
            $this->data->update('ca_shopping_cart',$where,array('qty'=>$cart['qty']+1));
        } else {
            $this->data->insert('ca_shopping_cart',array(
                'member_id'     => $_SESSION['web']['member']['member_id'],
                'pro_id'        => $pro_id,
                'name'          => $product['name'],
                'cate_id'       => $product['cate_id'],
                'picpath'       => $product['picpath_0'],
                'price'         => $product['price_0'],
                'acctime'       => time()
            ));
        }
        e_json('',1);
    }
}
